<?php 
/**
 * Class description
 *
 * @since 8 мая 2010
 * @author diotheos
 */
class Lib_Integrator_Site_Ria_Connector {
	private $_connection = null;
	private $_connectionName = null;
	/**
	 * Function description
	 *
	 * @since 8 мая 2010
	 * @author diotheos
	 */
	public function __construct(){
		echo "<div>Creating connector</div>";
	   $this->connect();
	   
	}
	/**
	 * Function description
	 * 
	 * @since 8 мая 2010
	 * @author diotheos
	 * @return void
	 */
	public function probe(){
//		$manager = Doctrine_Manager::getInstance();
//		$manager->
        $connection = $this->getConnection();
//        $options = array(
//		        "generateBaseClasses" => true,
//		        "generateTableClasses" => true
//		);
//		$connection->setAttribute(Doctrine::ATTR_AUTO_ACCESSOR_OVERRIDE, false);     
//        Doctrine::generateModelsFromDb(
//            APPLICATION_PATH . "../library/Lib/Integrator/Site/Ria/Model/Auto3",
//            array($connection->getName()),
//            $options
//        );
//        $connection->se
//        $connection->query('SET NAMES utf8');
        $result = $connection->fetchAll('
            select 
                *  
            from 
                marka_new m 
            inner join 
                model_new
            on
                model_new.marka_id = m.marka_id   
            where 
                m.lang_id = ?
            limit 10', 
            array(2)
        );
        echo "<pre>";
        	print_r($result);
        echo "</pre>";
	}
	/**
	 * Function description
	 * 
	 * @since 8 мая 2010
	 * @author diotheos
	 * @return void
	 */
	public function setConfig($configFile){
		
	}
	
	/**
	 * Function description
	 * 
	 * @since 8 мая 2010
	 * @author diotheos
	 * @return void
	 */
	public function connect($params = null){
		$connection = Doctrine_Manager::connection('mysql://master:gtnhjdbx@plan.ria.ua/auto3','Connection 2');
//        $connection = Doctrine_Manager::connection('mysql://root:asterion7@127.0.01/auto3_ria','Connection 2');
		$connection->exec("SET NAMES 'UTF8'");
		$this->setConnection($connection);
		echo "<div>Connecting to database</div>";
	}
	
	/**
	 * Function description
	 * 
	 * @since 8 мая 2010
	 * @author diotheos
	 * 
	 * @param Doctrine_Connection $connection
	 * @return void
	 */
	public function setConnection(Doctrine_Connection $connection){
		$this->_connection = $connection;
	}
	
	/**
	 * Function description
	 * 
	 * @since 8 мая 2010
	 * @author diotheos
	 * @return Doctrine_Connection
	 */
	public function getConnection(){
		return $this->_connection;
	}
	
	/**
	 * Function description
	 * 
	 * @since 8 мая 2010
	 * @author diotheos
	 * @return void
	 */
	public function setConnectionName($name){
		$this->_connectionName = $name;
	}
	/**
     * Function description
     * 
     * @since 8 мая 2010
     * @author diotheos
     * @return string
     */
	public function getConnectionName(){
		return $this->_connectionName;
	}
}